package com.itfenghuang.controller;

import com.itfenghuang.bean.Student;
import com.itfenghuang.service.StudentServiceImp;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 查询学生的Servlet功能类
 * 表示层:接受请求响应用户  目前来说: 写Servlet
 */
@SuppressWarnings("all")
public class GetStuServlet extends HttpServlet {

    private StudentServiceImp service=new StudentServiceImp();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.中文乱码问题
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //2.获取请求参数值
        String sname = req.getParameter("sname");
        String sage = req.getParameter("sage");

        List<Student> list=service.getStus(sname,sage);
        //首先,将集合存储到请求域中,然后转发到selectStudent.jsp上
        req.setAttribute("stuList",list);
        RequestDispatcher rd = req.getRequestDispatcher("/selectStudent.jsp");
        rd.forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req, resp);
    }
}



